package com.hx.thread.reentrant;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/**
 * @author jxlgcmh
 * @date 2019-07-31 21:54
 */
public class ReentLockExample {

    public static void main(String[] args) {
        ReentLockExample example = new ReentLockExample();
        ExecutorService service = Executors.newCachedThreadPool();
        service.submit(() -> example.fun());
        service.submit(() -> example.fun());
    }


    private Lock lock = new ReentrantLock();

    public void fun() {
        lock.lock();
        for (int i = 0; i < 5; i++) {
            System.out.print(i + "\t");
        }
        lock.unlock();
    }
}
